//
//  TransactionRecordsCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/1/28.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "TransactionRecordsCell.h"

@implementation TransactionRecordsCell{
    UIImageView     *imageV;
    QXLable         *labTitle;
    QXLable         *playLabTitle;

    QXLable         *labTime;
    QXLable         *labMoney;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
//PlayName
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        WS(weakSelf);
        imageV=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"pay_wechat"]];
        imageV.layer.masksToBounds=YES;
        imageV.layer.cornerRadius=25.0;
        [self.contentView addSubview:imageV];
        [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).with.offset(13);
            make.top.equalTo(weakSelf.contentView).with.offset(10);
            make.bottom.equalTo(weakSelf.contentView).with.offset(-10);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
        
        labTitle=[[QXLable alloc]initTitle];
        labTitle.text=@"微信充值";
        [labTitle sizeToFit];
        [self.contentView addSubview:labTitle];
        [labTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageV.mas_right).with.offset(13);
            make.top.equalTo(imageV).with.offset(4);
        }];
        
        //MARK:
        playLabTitle=[[QXLable alloc]initTitle];
        playLabTitle.text=@"PlayName";
        [self.contentView addSubview:playLabTitle];
        [playLabTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(labTitle);
            make.left.equalTo(labTitle.mas_right).with.offset(8);
        }];
        
        
        
        labTime=[[QXLable alloc]initWithFount:10];
        labTime.text=@"2017-09-12 19:09:35";
        [self.contentView addSubview:labTime];
        [labTime mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageV.mas_right).with.offset(13);
            make.bottom.equalTo(imageV).with.offset(-10);
        }];
        
        labMoney=[[QXLable alloc]initTitle];
        UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onclickEdit)];
        [labMoney addGestureRecognizer:tap];
        labMoney.numberOfLines=0;
        labMoney.textAlignment=NSTextAlignmentRight;
        [self.contentView addSubview:labMoney];
        [labMoney mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView).with.offset(-13);
            make.centerY.equalTo(weakSelf.contentView);
        }];
        
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(@.7);
        }];
    }
    return self;
}

- (void)setPlanModel:(PlanModel *)planModel{
    _planModel=planModel;
    
    [imageV sd_setImageWithURL:[NSURL URLWithString:planModel.Logo]];
    labTitle.text=planModel.LTypeName;
    playLabTitle.text = planModel.PlayName;
    labTime.text=[NSString stringWithFormat:@"第%@期",planModel.Issue];
    
    if (planModel.WinState==1) {
        if (self.userId&&(![[UserModel userModel].UserId isEqualToString:self.userId])) {
            labMoney.text=@"未开奖";
            labMoney.textColor=DEFAULTTEXTBLACKCOLOR;
            
        }else{
            labMoney.text=@"编辑\n未开奖";
            labMoney.userInteractionEnabled=YES;
            labMoney.textColor=DEFAULTTEXTBLACKCOLOR;
        }
        
    }else{
        labMoney.text=@"已开奖";
        labMoney.textColor=DEFAULTORANGECOLOR;
        labMoney.userInteractionEnabled=NO;
    }
    [labMoney setRightSpace:5];
    labMoney.font=[UIFont systemFontOfSize:13];
}

- (void)onclickEdit{
    if (self.editBlock) {
        self.editBlock(self.planModel);
    }
}

- (void)setRecordsModel:(PrepaidRecords *)recordsModel{
    _recordsModel=recordsModel;
    labMoney.text=@"";
    labMoney.textColor=DEFAULTORANGECOLOR;
    if (recordsModel.Type==1) {
        imageV.image=[self imageWithType:recordsModel.PayType];
        labTitle.text=[self titleWithType:recordsModel.PayType];
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@"+%.2f",recordsModel.Money];
    }else if (recordsModel.Type==2){
        imageV.image=[UIImage imageNamed:@"trading_withdrawal"];
        labTitle.text=[NSString stringWithFormat:@"%.2f",recordsModel.Money];
        labTime.text=recordsModel.SubTime;
        if (recordsModel.State==1) {
            labMoney.text=@"提现中";
        }else if (recordsModel.State==2){
            labMoney.text=@"已退回";
        }else if (recordsModel.State==3){
            labMoney.text=@"已到账";
        }
        labMoney.textColor=DEFAULTTEXTBLACKCOLOR;
        
    }else if (recordsModel.Type==3){
        [imageV sd_setImageWithURL:[NSURL URLWithString:recordsModel.LotteryIcon]];
        labTitle.text=recordsModel.UserName;
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@"点阅 -%.2f",recordsModel.Money];
    }else if (recordsModel.Type==4){
        [imageV sd_setImageWithURL:[NSURL URLWithString:recordsModel.LotteryIcon]];
        labTitle.text=recordsModel.UserName;
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@"点阅佣金 +%.2f",recordsModel.Money];
    }else if (recordsModel.Type==5){
        [imageV sd_setImageWithURL:[NSURL URLWithString:recordsModel.LotteryIcon]];
        labTitle.text=recordsModel.UserName;
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@"打赏 -%.2f",recordsModel.Money];
    }else if (recordsModel.Type==6){
        [imageV sd_setImageWithURL:[NSURL URLWithString:recordsModel.LotteryIcon]];
        labTitle.text=@"受邀奖励";
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@"受邀奖励 +%.2f",recordsModel.Money];
    }else if (recordsModel.Type==7){
        imageV.image=[UIImage imageNamed:@"trading_share"];
        labTitle.text=@"邀请奖励";
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@" +%.2f",recordsModel.Money];
    }else if (recordsModel.Type==8){
        imageV.image=[UIImage imageNamed:@"trading_topUp"];
        labTitle.text=@"任务奖励";
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@" +%.2f",recordsModel.Money];
    }else if (recordsModel.Type==9){
        [imageV sd_setImageWithURL:[NSURL URLWithString:recordsModel.LotteryIcon]];
        labTitle.text=recordsModel.UserName;
        labTime.text=recordsModel.SubTime;
        labMoney.text=[NSString stringWithFormat:@"打赏 +%.2f",recordsModel.Money];
    }
}

- (UIImage *)imageWithType:(NSInteger)type{
    if (type==1) {
        return [UIImage imageNamed:@"pay_wechat"];
    }else if (type==2){
        return [UIImage imageNamed:@"pay_alipay"];
    }else if (type==3){
        return [UIImage imageNamed:@"pay_union"];
    }
    return nil;
}

- (NSString *)titleWithType:(NSInteger)type{
    if (type==1) {
        return @"微信支付";
    }else if (type==2){
        return @"支付宝支付";
    }else if (type==3){
        return @"银联支付";
    }
    return nil;
}

@end
